<?php
/**
 * Create by Phpstorm
 * User: Peco
 * Date: 2019/11/20
 * Time: 14:47
 * CommonController.php
 */

namespace App\Http\Controllers\Api;

use App\Repositories\GoodsRepository;
use App\Repositories\PayRepository;
use App\Repositories\SmsRepository;
use App\Repositories\UserRepository;
use App\Services\AliOssSts;
use Illuminate\Http\Request;

class CommonController extends BaseAdminController
{
    /**
     * @var UserRepository 注入的UserRepository
     */
    private $userRepository;

    /**
     * @var GoodsRepository 注入的外部服务
     */
    protected $goodsRepository;

    /**
     * @var SmsRepository 注入的数据模型
     */
    protected $smsRepository;

    /**
     * @var PayRepository 注入的数据模型
     */
    protected $payRepository;

    /**
     * UserController constructor.
     * @param UserRepository $userRepository
     */
    public function __construct(UserRepository $userRepository,
                                GoodsRepository $goodsRepository,
                                SmsRepository $smsRepository,
                                PayRepository $payRepository){
        $this->userRepository = $userRepository;
        $this->goodsRepository = $goodsRepository;
        $this->smsRepository = $smsRepository;
        $this->payRepository = $payRepository;
    }
    /**
     * 返回oss sts权限
     * @return array
     */
    public function getAliOssSts()
    {
        return AliOssSts::getSts();
    }

    /**
     * @param Request $request
     * @return string
     */
    public function getHomeStatistics(Request $request){
        $userCount = $this->userRepository->getUserCountRepository();

        $goodsCount = $this->goodsRepository->getGoodsCountRepository();

        $smsCount = $this->smsRepository->getSmsCountRepository();

        $tradingCount = $this->payRepository->getTradingCountRepository();

        return \GuzzleHttp\json_encode(['data'=>
            ['user'=>$userCount, 'goods'=>$goodsCount,
            'sms'=>$smsCount, 'trading'=>$tradingCount]]);

    }
}
